<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var names = ["abc", "cba", "nba", "mba"]
    // 只有一个参数,()可以省略
    // 只有一行代码,那么{}可以省略
    names.forEach(item => console.log(item))

    var nums = [20, 30, 11, 15, 111]
    console.log(
      nums.filter(item => item % 2 === 0)
    )

    // 如果默认返回值是一个对象,那么这个对象必须加()
    var arrFn = () => ({ name: 'why' })
    console.log(arrFn())


    // nums的偶数平方和
    var result = nums
      .filter(item => item % 2 === 0)
      .map(item => item * item)
      .reduce((pre, item) => pre + item)
    console.log(result)

  </script>
</body>

</html>